clear
set more off
#delimit ;
/*****************************************************************************************************************;
**This dofile starts from the restricted BangladeshGPS data and generates expandedDHSGPS for each year separately;

other dataset this dofile also GENERATES for the matching of nearest clusters
BangladeshGPS_2004dropped

*****************************************************************************************************************/;

*****************************************************************************************************************;
*Paths;
*****************************************************************************************************************;

*access files in subdirectory generated by data creating dofiles;
*2004;
local indataset2004 "rawdta/DHS2004/BangladeshGPS_2004";
local outdataset2004 "dtafiles/expandedDHSGPS2004.dta";

*2007;
local indataset2007 "rawdta/DHS2007/BangladeshGPS_2007";
local outdataset2007 "dtafiles/expandedDHSGPS2007.dta";

*1999;
local indataset1999 "rawdta/DHS1999/BangladeshGPS_1999";
local outdataset1999 "dtafiles/expandedDHSGPS1999.dta";

*****************************************************************************************************************;
*Main;
*****************************************************************************************************************;


use "`indataset2004'", clear;

**Drop 2 duplicates randomly;
sort dhsid;
set seed 12345678;
gen rand=uniform();
sort dhsid rand;
by dhsid: gen count=_n;
drop if count==2;

compress;

*need this file for matching nearest clusters;
save "dtafiles/BangladeshGPS_2004dropped.dta", replace;

**Expands DHS data for merge with well data**;
expand 3534;

saveold "`outdataset2004'", replace;

use "`indataset2007'", clear;
compress;
expand 3534;

compress;
saveold "`outdataset2007'", replace;

use "`indataset1999'", clear;
compress;
expand 3534;

compress;
saveold "`outdataset1999'", replace;
